Skip to content

Rewrite how OneShotCfg.build_modes gets constructed - #158

Merged
rswarbrick merged 2 commits into
lowRISC:masterfrom
rswarbrick:one-shot-build-modes
Apr 7, 2026
Merged

rswarbrick merged 2 commits into
lowRISC:masterfrom
rswarbrick:one-shot-build-modes

Conversation

@rswarbrick

Copy link
Copy Markdown
Contributor

This is a bit tricky because self.build_modes comes from parsing an hjson dictionary and is actually a list of dictionaries that describe build modes.

These get parsed and converted to BuildMode objects by Mode.create_modes.

I've written a rather silly loose check that makes sure the types look reasonable, which is enough to let us convince Pyright to allow the code to claim the correct eventual types.

This commit also fixes an incorrect type in the second argument to create_modes.

Comment thread src/dvsim/flow/one_shot.py Resolved
Comment thread src/dvsim/modes.py Resolved
@rswarbrick
rswarbrick force-pushed the one-shot-build-modes branch 2 times, most recently from 72db86b to a39dcd6 Compare April 4, 2026 17:40
@rswarbrick
rswarbrick requested a review from AlexJones0 April 4, 2026 17:42

@AlexJones0 AlexJones0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, modulo a few nits.

Comment thread src/dvsim/modes.py Resolved
Comment thread src/dvsim/flow/one_shot.py Resolved
Comment thread src/dvsim/flow/one_shot.py Resolved
@rswarbrick
rswarbrick force-pushed the one-shot-build-modes branch 2 times, most recently from 7459809 to ca34a98 Compare April 6, 2026 20:51
@rswarbrick
rswarbrick requested a review from AlexJones0 April 6, 2026 20:51
This is equivalent to the code before (although the call sites get
slightly nicer). The important thing is that a type checker can now
tell more about the type of the created mode objects: if I call
BuildMode.create_modes(...), the type checker can tell that I create a
list of BuildMode objects (rather than only knowing that they are Mode
objects).

Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
This is a bit tricky because self.build_modes comes from parsing an
hjson dictionary and is actually a list of dictionaries that describe
build modes.

These get parsed and converted to BuildMode objects by
Mode.create_modes.

I've written a rather silly loose check that makes sure the types look
reasonable, which is enough to let us convince Pyright to allow the
code to claim the correct eventual types.

Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
@rswarbrick
rswarbrick force-pushed the one-shot-build-modes branch from ca34a98 to 4b2d4bc Compare April 7, 2026 15:50

@machshev machshev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rswarbrick

@AlexJones0 AlexJones0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a very nice improvement.

@rswarbrick
rswarbrick added this pull request to the merge queue Apr 7, 2026
Merged via the queue into lowRISC:master with commit c471598 Apr 7, 2026
6 checks passed
@rswarbrick
rswarbrick deleted the one-shot-build-modes branch April 7, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants